package org.knot.mockejb3.annotation;

import java.util.Map;


/**
 * 对注释Remove的处理
 * 
 * @author yuxiaowei
 *
 */
public class RemoveAnnotationRuleImpl implements AnnotationRule, org.knot.mockejb3.annotation.lifeCycle.Remove{

   public void invoke(RuleParams params) throws Exception {
       
//        Object[] os =  new Object[]{};
//        if (params.getMethod().getParameterTypes().length!=0)
//        {
//            os =  new Object[params.getMethod().getParameterTypes().length];
//        }
//        params.getMethod().invoke(params.getSessionBean().getBean(), os);
        
        
        //调用该对象的销毁前方法
        Map<AnnotationRule, RuleParams> mm = AnnotationRuleManager.getInstance().getClasseAnnotations().get(params.getSessionBean()).getAnnotations();
        for (AnnotationRule rule : mm.keySet()) {
            // PreDestroy
            if (rule instanceof org.knot.mockejb3.annotation.lifeCycle.PreDestroy) {
                rule.invoke(mm.get(rule));
            }
        }
        
        //释放关联对象
        AnnotationRuleManager.getInstance().getStateFulBeanMap().remove(params.getKey()).remove(params.getSessionBean());
        AnnotationRuleManager.getInstance().getClasseAnnotations().remove(params.getSessionBean());
        params = null;
        
    }
   
}
